package cn.e2win.base.entity;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "sys_function")
public class SysFunction extends BaseEntity implements Comparable<SysFunction>{

	private static final long serialVersionUID = 1L;
	
	@Id
	@Basic(optional = false)
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id", nullable = false)
	private Integer id;
	
	@Column(name="title",length=128)
	private String title;

	@Transient
	private Integer enable;
	
	@Column(name="description",length=1000)
	private String description;
	
	@Column(name="URL",length=256)
	private String url;
	
	@Column(name="orderMark",length=5)
	private Integer orderMark;
	
	@ManyToOne
	@JoinColumn(name="menuId")
	private SysMenu menu;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Integer getEnable() {
		return enable;
	}

	public void setEnable(Integer enable) {
		this.enable = enable;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public Integer getOrderMark() {
		if(orderMark == null || orderMark.intValue() == 0) {
			return this.id;
		}
		return orderMark;
	}

	public void setOrderMark(Integer orderMark) {
		this.orderMark = orderMark;
	}

	public SysMenu getMenu() {
		return menu;
	}

	public void setMenu(SysMenu menu) {
		this.menu = menu;
	}
	
	public String getEntity(){
		return this.url.split("/")[1];
	}

	@Override
	public int compareTo(SysFunction o) {
		// TODO Auto-generated method stub
		return this.getOrderMark().compareTo(o.getOrderMark());
	}

}
